<template>
	<view class="task-custom" :style="style"
		:class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor,radius?'bottom-radius':'']">
		<view class="task-bar cu-bar">
			<view class="action" @tap="BackPage" v-if="isBack">
				<text class="cuIcon-back"></text>
				<slot name="backText"></slot>
			</view>
			<view class="content">
				<slot name="content"></slot>
			</view>
			<slot name="btn"></slot>
		</view>
		<slot name="cumul"></slot>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: uni.getWindowInfo().statusBarHeight
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var bgImage = this.bgImage;
				var style = `padding-top:${this.StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
			radius: {
				type: Boolean,
				default: false
			},
			isBackTips: {
				type: [Boolean, String],
				default: false
			},
			tisContent: {
				type: String,
				default: ''
			},
			customModal: {
				type: [Boolean, String],
				default: false
			},
		},
		methods: {
			BackPage() {
				const _this = this
				if (this.isBackTips) {
					// 自定义提示弹框
					if (this.customModal) {
						return uni.$showModal({
							title: '提示',
							content: this.tisContent,
							contentColor: "#ff0000",
							titleColor: "#ff0000",
							showCancel: true,
							isStatus: 2,
							success: function(res) {
								if (res.confirm) {
									setTimeout(() => {
										_this.$emit('saveData')
									}, 500)
								}
							}
						})
					}
					uni.$showModal({
						title: '提示',
						content: this.tisContent,
						showCancel: true,
						success(res) {
							if (res.confirm) {
								uni.navigateBack({
									delta: 1
								});
							}
						}
					})
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
				// uni.navigateBack({
				// 	delta: 1
				// });
			}
		}
	}
</script>

<style scoped>
	.task-custom {
		position: fixed;
		width: 100%;
		top: 0;
		z-index: 999;
	}

	.task-custom.bottom-radius {
		border-bottom-left-radius: 30rpx;
		border-bottom-right-radius: 30rpx;
	}

	.task-bar {
		height: 60rpx;
		line-height: 60rpx;
		position: relative;
		display: flex;
		justify-content: space-between;
	}

	.task-bar .content {
		position: absolute;
		text-align: center;
		width: calc(100% - 340rpx);
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		margin: auto;
		cursor: none;
		pointer-events: none;
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}

	.cuIcon-back {
		margin-right: 15rpx;
	}
</style>
